configure_file(pandaVersion.h.in pandaVersion.h)
configure_file(checkPandaVersion.h.in checkPandaVersion.h)
configure_file(checkPandaVersion.cxx.in checkPandaVersion.cxx)

if(CMAKE_CXX_STANDARD GREATER 16)
  # This serves as a reminder to update checkPandaVersion.h.in when we upgrade
  # to C++17, which supports inline variables - a cleaner way of depending on
  # the Panda version symbol from a header than what we're currently doing.
  message(FATAL_ERROR "Developer notice: Update checkPandaVersion.h.in for C++17!")
endif()

set(P3DTOOLBASE_HEADERS
  ${CMAKE_CURRENT_BINARY_DIR}/checkPandaVersion.h
  ${CMAKE_CURRENT_BINARY_DIR}/pandaVersion.h
  addHash.I addHash.h
  atomicAdjust.h
  atomicAdjustDummyImpl.h atomicAdjustDummyImpl.I
  atomicAdjustGccImpl.h atomicAdjustGccImpl.I
  atomicAdjustI386Impl.h atomicAdjustI386Impl.I
  atomicAdjustPosixImpl.h atomicAdjustPosixImpl.I
  atomicAdjustWin32Impl.h atomicAdjustWin32Impl.I
  cmath.I cmath.h
  deletedBufferChain.h deletedBufferChain.I
  deletedChain.h deletedChain.T
  dtoolbase.h dtoolbase_cc.h dtoolsymbols.h
  dtool_platform.h
  fakestringstream.h
  indent.I indent.h
  memoryBase.h
  memoryHook.h memoryHook.I
  mutexImpl.h
  mutexDummyImpl.h mutexDummyImpl.I
  mutexPosixImpl.h mutexPosixImpl.I
  mutexWin32Impl.h mutexWin32Impl.I
  mutexSpinlockImpl.h mutexSpinlockImpl.I
  nearly_zero.h
  neverFreeMemory.h neverFreeMemory.I
  numeric_types.h
  pdtoa.h
  pstrtod.h
  register_type.I register_type.h
  selectThreadImpl.h
  stl_compares.I stl_compares.h
  typeHandle.I typeHandle.h
  typeRegistry.I typeRegistry.h
  typeRegistryNode.I typeRegistryNode.h
  typedObject.I typedObject.h
  pallocator.T pallocator.h
  pdeque.h plist.h pmap.h pset.h
  pvector.h epvector.h
  lookup3.h
  version.h
)

set(P3DTOOLBASE_SOURCES
  ${CMAKE_CURRENT_BINARY_DIR}/checkPandaVersion.cxx
  addHash.cxx
  atomicAdjustDummyImpl.cxx
  atomicAdjustI386Impl.cxx
  atomicAdjustPosixImpl.cxx
  atomicAdjustWin32Impl.cxx
  deletedBufferChain.cxx
  dtoolbase.cxx
  indent.cxx
  lookup3.c
  memoryBase.cxx
  memoryHook.cxx
  mutexDummyImpl.cxx
  mutexPosixImpl.cxx
  mutexWin32Impl.cxx
  mutexSpinlockImpl.cxx
  neverFreeMemory.cxx
  pdtoa.cxx
  pstrtod.cxx
  register_type.cxx
  typeHandle.cxx
  typeRegistry.cxx typeRegistryNode.cxx
  typedObject.cxx
)

set(P3DTOOLBASE_IGATEEXT
  typeHandle_ext.cxx
  typeHandle_ext.h
)

set_source_files_properties(indent.cxx PROPERTIES SKIP_UNITY_BUILD_INCLUSION YES)

composite_sources(p3dtoolbase P3DTOOLBASE_SOURCES)
add_component_library(p3dtoolbase NOINIT SYMBOL BUILDING_DTOOL_DTOOLBASE
  ${P3DTOOLBASE_HEADERS} ${P3DTOOLBASE_SOURCES})
# Help other libraries find the autogenerated headers
target_include_directories(p3dtoolbase PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
  $<BUILD_INTERFACE:${PANDA_OUTPUT_DIR}/include>)
target_link_libraries(p3dtoolbase PKG::EIGEN PKG::THREADS)
target_interrogate(p3dtoolbase ${P3DTOOLBASE_SOURCES} EXTENSIONS ${P3DTOOLBASE_IGATEEXT})

if(NOT BUILD_METALIBS)
  install(TARGETS p3dtoolbase
    EXPORT Core COMPONENT Core
    DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/panda3d
    ARCHIVE COMPONENT CoreDevel)
endif()
install(FILES ${P3DTOOLBASE_HEADERS} COMPONENT CoreDevel DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/panda3d)
